﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GbmpModel.h"
#include "ElementId.h"
#include "IModelView.h"
#include "Vector3d.h"

namespace gcmp
{
    class IModelView;

    class GBMP_MODEL_EXPORT IGbmpModelView
    {
    public:
        virtual ~IGbmpModelView();

    public:
        static IGbmpModelView* GetGbmpModelView(IModelView* pModelView);

        static const IGbmpModelView* GetGbmpModelView(const IModelView* pModelView);

        virtual ElementId GetElementId() const = 0;

        virtual std::wstring GetViewType() const = 0;

        virtual IModelView* GetModelView() = 0;
        virtual const IModelView* GetModelView() const = 0;

        virtual Vector3d GetOrigin() const = 0;
        virtual bool SetOrigin(const Vector3d& origin) = 0;

        virtual const std::wstring& GetUserViewTypeName() const = 0;
        virtual bool SetUserViewTypeName(const std::wstring viewType) = 0;

        virtual ElementId GetWorkLevelId() const = 0;
        virtual bool SetWorkLevelId(ElementId worklevelId) = 0;

        virtual ElementId GetViewSymbolId() const = 0;
        // 在接口中暴露GCMP视图的方法时，下面的宏中也需相应增加
    };
}

#define DECLARE_MODEL_VIEW_BASE_METHODS \
    virtual IModelView* GetModelView() override; \
    virtual const IModelView* GetModelView() const override; \
    virtual Vector3d GetOrigin() const override; \
    virtual bool SetOrigin(const Vector3d& origin) override;\
    virtual ElementId GetViewSymbolId() const override;

#define DEFINE_MODEL_VIEW_BASE_METHODS(CLASS_NAME) \
    IModelView* CLASS_NAME::GetModelView() { return quick_cast<IModelView>(GetOwnerElement()); } \
    const IModelView* CLASS_NAME::GetModelView() const { return quick_cast<const IModelView>(GetOwnerElement()); } \
    Vector3d CLASS_NAME::GetOrigin() const { return GetModelView()->GetOrigin(); } \
    bool CLASS_NAME::SetOrigin(const Vector3d& origin) { return GetModelView()->SetOrigin(origin); }\
    ElementId CLASS_NAME::GetViewSymbolId() const {\
        const IModelView *pModelView=GetModelView();\
        DBG_WARN_AND_RETURN_UNLESS(pModelView,ElementId::InvalidID,L"invalid pModelView",L"GDMPLab",L"2024-03-30");\
        return pModelView->GetViewSymbolId();\
        }
